using System;
using System.Runtime.CompilerServices;
using Core;
using Core.Base;
using Core.Extension;
using Global.Game;
using Global.Model;
using Global.Module;
using Logic.Hall.Mgr;
using UnityEngine;
using UnityEngine.UI;

namespace Global.Hall
{
    public class HallPanel : BasePanel<HallPanel>
    {
        public Button btnGameScene;
        public Button btnEventTest;
        private Observable<UserParam> userParam = new Observable<UserParam>();

        public override void OnInit()
        {
            base.OnInit();
            btnGameScene.BindEvent(delegate { KKGL.SceneMgr.LoadSceneAsync<GameModule>("Game", OnClose); });
            btnEventTest.BindEvent(delegate { KKGL.UIEvent.Notify(EHall.TestRobot); });
            KKGL.UIEvent.RegHandler(EHall.TestRobot, TestRobot, TokenSource.Token);

            userParam.AddListener(delegate(UserParam param) { Debug.Log($"发生改变！，{param.name}今年{param.age}岁。"); });
            userParam.Value = new UserParam
            {
                name = "小明",
                age = 12
            };
        }

        private void TestRobot(ITuple tuple)
        {
            // Debug.Log("Robot Run--------------Hall");
            // Debug.Log(KKGL.ModelMgr.RetrieveModel<UserModel>().age);
            // Debug.Log(UserModel.Ins.age);
            userParam.Value.age++;
        }
    }


    public class UserParam
    {
        public string name;
        public int age;
    }
}